﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TimbreRecognition.Recognition.Model;

namespace TimbreRecognition.Recognition
{
    public class NeuronNetworkWorker
    {
        private readonly INetwork network;

        private readonly NetworkClassifierWrapper classifier;

        public NeuronNetworkWorker(INetwork network)
        {
            this.network = network;
            classifier = new NetworkClassifierWrapper(network);
        }

        public List<double[]> ClassifyBatch(IEnumerable<double[]> data)
        {
            List<double[]> classes = new List<double[]>();
            foreach (double[] elements in data)
            {
                double[] result = Classify(elements);
                classes.Add(result);
            }

            return classes;
        }

        public List<double[]> GetOutoutBatch(IEnumerable<double[]> data)
        {
            List<double[]> output = new List<double[]>();
            foreach (double[] elements in data)
            {
                double[] result = GetOutput(elements);
                output.Add(result);
            }

            return output;
        }

        public double[] Classify(double[] data)
        {
            //if (data.Any(o => o > 1 || o < 0)) {
            //    throw new ArgumentException("Values must be normalized on 1");
            //}

            classifier.recalculateOutput(data);
            return classifier.getOutput();
        }

        public double[] GetOutput(double[] data)
        {
            //if (data.Any(o => o > 1 || o < 0))
            //{
            //    throw new ArgumentException("Values must be normalized on 1");
            //}

            network.recalculateOutput(data);
            return network.getOutput();
        }
    }
}
